package com.yb.livewykt.util

import android.hardware.Camera
import android.hardware.Camera.CameraInfo

class CameraUtils {

    companion object{
        /**
         * 获取前置相机的方向
         *
         * @return
         */
        fun getFrontCameraOrientation(): Int {
            val info = CameraInfo()
            var cameraId = -1
            val numCameras = Camera.getNumberOfCameras()
            for (i in 0 until numCameras) {
                Camera.getCameraInfo(i, info)
                if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
                    cameraId = i
                    break
                }
            }
            return if (cameraId < 0) {
                // no front camera, regard it as back camera
                90
            } else {
                info.orientation
            }
        }
    }

}